/** DICE's configuration engine */
module dice.config;

class Config
{
	/** Actually save the option to disk, or at least queue it for disk */
	void save (char[] option, char[] value)
	{
	}
	
	void delegate() [char[]] watchers;
	
	char[][char[]] options;
	
	/** Set the option to the value */
	void set (char[] option, char[] value)
	{
		/* Set the option */
		options[option] = value;
		
		/* Inform any watchers */
		if (option in watchers)
		{
			watchers[option]();
		}
		
		/* Flush to disk/send to server/.. */
		save(option, value);
	}
	
	/** Watch an option.
	 * 
	 *  TODO: allow more than one function to watch an option.
	 */
	void watch (char[] option, void delegate() callback)
	{
		watchers[option] = callback;
	}
	
	/** Get the option, or return value if not set */
	char[] get (char[] option, char[] value)
	{
		if (option in options)
			return options[option];
		return value;
	}
}
